<?php
/**
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/



if(!isset($semf_root) )
{
	$semf_root = '../';
	
	$component_type=$_GET['component'];
	$component_id=$_GET['id'];
	$component_container=$_GET['container'];
	$page_xml = $_GET['page_xml'];
	$key = $_GET['key'];
	$value = $_GET['value'];
	$property_group = $_GET['property_group'];

	// Define that we are returning XML content & not to cache:
	header('Content-Type: text/xml');
	header('Cache-control: no-cache');
}
//for save and load properties..
include_once($semf_root."page_designer/util/properties.php");
include_once($semf_root."page_designer/util/backup.php");

include_once($semf_root."page_designer/util/change_property_util.php");


// build the xml
if(isset($from_plugin) && $from_plugin == 1)
{
	$doc = $page_doc;
}
else
{
	$doc = new DOMDocument();
	$parent = NULL;
	
	if (file_exists($page_xml)) {
		$doc->load($page_xml);
		$doc->validate();
	}
	else
	{
		exit();
	}
}


//echo " component_container is : $component_container";
if ( !isset($component_container) || $component_container==NULL || 
						$component_container == 'null') //this come from js  
{
	$parent = $doc->documentElement;
}
else
{
	$parent = $doc->getElementById($component_container);
}
$component = $doc->getElementById($component_id);



if( $component != NULL )
{
	//echo $doc->saveXML($parent->firstChild);
	adjust_properties($semf_root, $doc, $component, $parent, $property_group, $key, $value);
}

if(!isset($from_plugin))
{
	savePageXML($doc, $page_xml);
}

/** now just open the existing xml */
$not_starter = 1;

if(!isset($from_plugin))
{
	include("open_existing.php");
}

if(isset($from_plugin))
{
	$page_doc = $doc;
}


?>